package com.example.demo.controller;

import com.example.demo.pojo.Result;
import com.example.demo.pojo.User;
import com.example.demo.servers.Userserver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class Usercontroller {
    @Autowired
    private Userserver userserver;
    @GetMapping
    public Result getalluser(){
        List<User> users= userserver.selectall();
        return Result.success(users);
    }
    @GetMapping("/{id}")
    public Result getuser(@PathVariable Integer id){
       User user= userserver.selectbyid(id);
        return Result.success(user);
    }

    @PostMapping
    public Result adduser(@RequestBody User user){
        userserver.adduser(user);
        return Result.success();
    }
    @PutMapping("/update")
    public Result updateuser(@RequestBody User user){
        userserver.update(user);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteuser(@PathVariable Integer id){
        userserver.delectbyid(id);
        return Result.success();
    }

}
